home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-23 | 1.1 KB | 40 lines | [TEXT/GEOL] |
- Item 9284939 23-April-90 11:34PDT
-
- From: DEREK White, Derek
-
- To: CPLUS.DEV$ C++ Interest List--Developers
- CPLUS.APPLE$ C++ Interest List--Apple Employees
-
- Sub: Copy Cconstructors & op=
-
- My latest thoughts have been about copy constructors and assignment
- operators. I've seen sugestions in several places that if you define one you
- should define the other, but I don't know how (or if) they should differ. If
- they should be the same, couldn't (shouldn't) the copy constructor just call
- the assignment operator to keep down on redundant code?:
-
- class TRect {
- int fint;
- public:
- TRect(const TRect& r);
- virtual TRect& operator=(const TRect& r);
- };
-
- TRect::TRect(const TRect& r)
- {
- *this = r; // "TRect::operator=(r)"
- }
-
- TRect& TRect::operator=(const TRect& r)
- {
- fint = r.fint; // etc...
- return *this;
- }
-
- As a second issue, does someone have a short example of how virtual
- assignment operators can be used even though they aren't inherited?
-
- Thanks,
- Derek White
-
-